using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.MedicalDomain;
using ShivamEMR.Model.DataInterfaces.MedicalDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Medical.Controllers
{   
    public class TreatmentTypeController : Controller
    {
		private readonly ITreatmentTypeRepository treatmenttypeRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public TreatmentTypeController()// : this(new TreatmentTypeRepository())
        {
            this.treatmenttypeRepository = Registry.RepositoryFactory.GetTreatmentTypeRepository();
        }

        public TreatmentTypeController(ITreatmentTypeRepository treatmenttypeRepository)
        {
			this.treatmenttypeRepository = treatmenttypeRepository;
        }

        //
        // GET: /TreatmentType/

        public ViewResult Index()
        {
            return View(treatmenttypeRepository.All);//Including(treatmenttype => treatmenttype.Treatments));
        }

        //
        // GET: /TreatmentType/Details/5

        public ViewResult Details(int id)
        {
            return View(treatmenttypeRepository.Find(id));
        }

        //
        // GET: /TreatmentType/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /TreatmentType/Create

        [HttpPost]
        public ActionResult Create(TreatmentType treatmenttype)
        {
            if (ModelState.IsValid) {
                treatmenttypeRepository.InsertOrUpdate(treatmenttype);
                treatmenttypeRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /TreatmentType/Edit/5
 
        public ActionResult Edit(int id)
        {
             return View(treatmenttypeRepository.Find(id));
        }

        //
        // POST: /TreatmentType/Edit/5

        [HttpPost]
        public ActionResult Edit(TreatmentType treatmenttype)
        {
            if (ModelState.IsValid) {
                treatmenttypeRepository.InsertOrUpdate(treatmenttype);
                treatmenttypeRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /TreatmentType/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(treatmenttypeRepository.Find(id));
        }

        //
        // POST: /TreatmentType/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var t = treatmenttypeRepository.Find(id);
            treatmenttypeRepository.Delete(t);
            treatmenttypeRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

